package org.gpp.proj1.test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.gpp.proj1.map.GameMap;
import org.gpp.proj1.map.MalformedMapFileException;
import org.gpp.proj1.map.parser.MapFileParser;

import com.jme.util.LoggingSystem;

import easyaccept.EasyAccept;

/**
 * 
 * @author Gustavo de Farias
 */
public class MapFileParserFacade {
	
	private Map<String, GameMap> gameMaps;

	/**
	 * 
	 */
	public MapFileParserFacade() {
		// Disabling logging
		LoggingSystem.getLoggingSystem().loggerOn( false );
		
		this.gameMaps = new HashMap<String, GameMap>();
	}
	
	/**
	 * @param mapFile
	 * @return
	 * @throws IOException
	 * @throws MalformedMapFileException
	 */
	public String loadMap(String mapFile) throws IOException, MalformedMapFileException {
		
		File f = new File(mapFile);
		String mapName = f.getName().substring(0, f.getName().lastIndexOf("."));
		
		this.gameMaps.put(mapName, MapFileParser.parseFile(mapFile));
				
		return mapName;
	}
	
	/**
	 * @param map
	 * @return
	 */
	public int getMapWidth(String map) {
		
		return this.gameMaps.get(map).getMapWidth();
	}
	
	/**
	 * @param map
	 * @return
	 */
	public int getMapLength(String map) {
		
		return this.gameMaps.get(map).getMapLength();
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public byte getHeight(String map, int l, int c) {
		
		return this.gameMaps.get(map).getHeights()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public byte getModifier(String map, int l, int c) {
		
		return this.gameMaps.get(map).getModifiers()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @param layer
	 * @return
	 */
	public byte getTopTexture(String map, int l, int c) {
		
		return this.gameMaps.get(map).getTopTextures()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public byte getSideTexture(String map, int l, int c) {
		
		return this.gameMaps.get(map).getSideTextures()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public String getDecorationModel(String map, int l, int c) {
		
		return this.gameMaps.get(map).getDecorationModels()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public int getDecorationTexture(String map, int l, int c) {
		
		return this.gameMaps.get(map).getDecorationTextures()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @return
	 */
	public float getDecorationScale(String map, int l, int c) {
		return this.gameMaps.get(map).getDecorationScales()[l][c];
	}
	
	/**
	 * @param map
	 * @param l
	 * @param c
	 * @param coordinate
	 * @return
	 */
	public float getDecorationRotation(String map, int l, int c, String coordinate) {
		if (coordinate.toLowerCase().equals("x")) {
			return this.gameMaps.get(map).getDecorationRotations()[l][c][0];
		}
		else if (coordinate.toLowerCase().equals("y")) {
			return this.gameMaps.get(map).getDecorationRotations()[l][c][1];
		}
		else if (coordinate.toLowerCase().equals("z")) {
			return this.gameMaps.get(map).getDecorationRotations()[l][c][2];
		}
		
		throw new RuntimeException("Invalid coordinate");
	}
	
	public static void main(String[] args) {
		args = new String[]{"org.gpp.proj1.test.MapFileParserFacade", "test/map_file_parser_test.txt"};
		EasyAccept.main(args);
	}
}